package com.quanyan.ic.parkingLot.http.service.impl;

import com.quanyan.ic.common.http.APIResponse;
import com.quanyan.ic.parkingLot.constants.ParkingLotConstants;
import com.quanyan.ic.parkingLot.http.service.BaseService;
import com.quanyan.ic.parkingLot.http.service.ParkingLotService;
import com.quanyan.ic.parkingLot.model.HikApiResponse;
import com.quanyan.ic.parkingLot.model.request.ReqParkingEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 停车场控制
 * Created by zhang on 17/8/22.
 */
@Service
public class ParkingLotServiceImpl implements ParkingLotService {
    private final static Logger logger = LoggerFactory.getLogger(ParkingLotServiceImpl.class);
    @Autowired
    private BaseService baseService;
    /**
     * 控制道闸确认进入
     * @param reqParkingEntry
     * @return
     */
    @Override
    public APIResponse entry(ReqParkingEntry reqParkingEntry) {
        HikApiResponse response = baseService.deviceControl(reqParkingEntry.getRoadwaySyscode(), ParkingLotConstants.ControlCommand.COMMAND_OPEN);
        if (response != null && response.getErrorCode() == 0) {
            return APIResponse.returnSuccess();
        } else {
            logger.error("确认进入失败：失败车道：【{}】；失败用户：【{}】；失败时间：【{}】；失败信息：{}",reqParkingEntry.getRoadwaySyscode(),reqParkingEntry.getOpenId(),new Date(),response.getErrorMessage());
            return APIResponse.returnFail(response.getErrorMessage());
        }
    }
}
